var Animations = {
	
	yscale: function(obj, h, d) {
		new Effect.Morph(obj, {
			style: { height: h + 'px' },
			duration: .6,
			queue: 'start'
		});
	},
	
	xscale: function(obj, w, d) {
		new Effect.Morph(obj, {
			style: { width: w + 'px' },
			duration: .6,
			queue: 'start'
		});
	},
	
	closePopup: function() {
		new Effect.Fade($('fastEditWrapper').parentNode, {duration: .3, afterFinishInternal: function() {
			$('fastEditWrapper').style.left = '2000px';
			Element.remove($('fastEditWrapper'));
		}, queue: 'start'});
		new Effect.Fade($('fadeLayerWrapper'), {duration: .3, afterFinishInternal: function() {
			$('fadeLayerWrapper').style.left = '2000px';
			Element.remove('popupWrapper');
		}, queue: 'end'});
	},
	
	showEditUserPopup: function(userName) {
		new Effect.Morph('fadeLayerWrapper', {
			style: {
				width:FF.getElementSize('contents')['w'] + 10 +'px', 
				height:FF.getElementSize('contents')['h'] + 10 +'px',
				top:FF.getElementSize('contents')['t']+'px', 
				left:'0px'
			},
			duration: 0,
			queue: 'start'
		});
		new Effect.Appear('fadeLayerWrapper', {duration: .3, from: 0, to: .65, afterFinishInternal: function() {
			// Creo il popup
			var popup = FF.visual.createPopup();
			popup.style.width = '500px';
			new Effect.Morph(popup, {
				style: {
					width:'500px', 
					height:'350px',
					top:Number(FF.getElementSize('contents')['h'] / 2 - 225) + 'px', 
					left:Number(FF.getElementSize('contents')['w'] / 2 - 300) + 'px'
				},
				duration: 0, 
				afterFinishInternal: function() {
					new Effect.Appear(popup, {duration: .2, afterFinishInternal: function() {
						popup.innerHTML = '<div class="fastEditContainer" id="fastEditWrapper"><div style="position:absolute; top: 8px; right:8px"><a href="javascript:Animations.closePopup();"><strong>X</strong></a></div><iframe width="100%" height="345" border="0" frameborder="0" scrolling="no" src="config_editUser.php?userName='+userName+'"></iframe></div>';
						$('contents').appendChild(popup);
					}});
				}
			});
		}});
	},
	
	showVirtualCrossfieldPopup: function(field) {
		
		new Effect.Morph('fadeLayerWrapper', {
			style: {
				width:FF.getElementSize('contents')['w'] + 10 +'px', 
				height:FF.getElementSize('contents')['h'] + 10 +'px',
				top:FF.getElementSize('contents')['t']+'px', 
				left:'0px'
			},
			duration: 0,
			queue: 'start'
		});
		new Effect.Appear('fadeLayerWrapper', {duration: .3, from: 0, to: .65, afterFinishInternal: function() {
			// Creo il popup
			var popup = FF.visual.createPopup();
			popup.style.width = '500px';
			new Effect.Morph(popup, {
				style: {
					width:'500px', 
					height:'350px',
					top:Number(FF.getElementSize('contents')['h'] / 2 - 225) + 'px', 
					left:Number(FF.getElementSize('contents')['w'] / 2 - 300) + 'px'
				},
				duration: 0, 
				afterFinishInternal: function() {
					new Effect.Appear(popup, {duration: .2, afterFinishInternal: function() {
						popup.innerHTML = '<div class="fastEditContainer" id="fastEditWrapper"><div style="position:absolute; top: 8px; right:8px"><a href="javascript:FF.contents.closeVirtualCrossfieldPopup();"><strong>X</strong></a></div><iframe width="100%" height="345" border="0" frameborder="0" scrolling="no" src="config_crossFieldsVirtual.php?field='+field+'"></iframe></div>';
						$('contents').appendChild(popup);
					}});
				}
			});
		}});
			
	},
	
	showCrossfieldPopup: function(field) {
		
		new Effect.Morph('fadeLayerWrapper', {
			style: {
				width:FF.getElementSize('contents')['w'] + 10 +'px', 
				height:FF.getElementSize('contents')['h'] + 10 +'px',
				top:FF.getElementSize('contents')['t']+'px', 
				left:'0px'
			},
			duration: 0,
			queue: 'start'
		});
		new Effect.Appear('fadeLayerWrapper', {duration: .3, from: 0, to: .65, afterFinishInternal: function() {
			// Creo il popup
			var popup = FF.visual.createPopup();
			popup.style.width = '500px';
			new Effect.Morph(popup, {
				style: {
					width:'600px', 
					height:'350px',
					top:Number(FF.getElementSize('contents')['h'] / 2 - 175) + 'px', 
					left:Number(FF.getElementSize('contents')['w'] / 2 - 300) + 'px'
				},
				duration: 0, 
				afterFinishInternal: function() {
					new Effect.Appear(popup, {duration: .2, afterFinishInternal: function() {
						popup.innerHTML = '<div class="fastEditContainer" id="fastEditWrapper"><div style="position:absolute; top: 8px; right:8px"><a href="javascript:FF.contents.closeCrossfieldPopup();"><strong>X</strong></a></div><iframe width="100%" height="345" border="0" frameborder="0" scrolling="no" src="config_crossFields.php?field='+field+'"></iframe></div>';
						$('contents').appendChild(popup);
					}});
				}
			});
		}});
			
	},
	
	showFastEditPopup: function(popup, elem) {
		new Effect.Morph('fadeLayerWrapper', {
			style: {
				width:FF.getElementSize('contents')['w'] + 10 +'px', 
				height:FF.getElementSize('contents')['h'] + 10 +'px',
				top:FF.getElementSize('contents')['t']+'px', 
				left:'0px'
			},
			duration: 0,
			queue: 'start'
		});
		new Effect.Appear('fadeLayerWrapper', {duration: .3, from: 0, to: .65, afterFinishInternal: function() {
			// Creo il popup
			new Effect.Morph(popup, {
				style: {
					width:'400px', 
					height:'350px',
					top:Number(FF.getElementSize('contents')['h'] / 2 - 175) + 'px', 
					left:Number(FF.getElementSize('contents')['w'] / 2 - 200) + 'px'
				},
				duration: 0, 
				afterFinishInternal: function() {
					new Effect.Appear(popup, {duration: .2, afterFinishInternal: function() {
						popup.innerHTML = '<div class="fastEditContainer" id="fastEditWrapper"><div class="popupCloseButton"><a href="javascript:FF.contents.closeFastEdit();"><strong>X</strong></a></div><iframe width="100%" height="345" border="0" frameborder="0" scrolling="no" src="fastEditor.php?field='+elem.getAttribute('name')+'&id='+elem.parentNode.parentNode.getAttribute('id').split("row_")[1]+'&idField='+$F('idField')+'&table='+$F('tableName')+'"></iframe></div>';
						$('contents').appendChild(popup);
					}});
				}
			});
		}});
			
	}
	
}

Animations.Popup = {
	
	ready: false,
	
	setFadeLayerDims: function() {
		new Effect.Morph('fadeLayerWrapper', {
			style: {
				width:FF.getElementSize('contents')['w'] + 10 +'px', 
				height:FF.getElementSize('contents')['h'] + 10 +'px',
				top:FF.getElementSize('contents')['t']+'px', 
				left:'0px'
			},
			duration: 0,
			queue: 'start'
		});	
	},
	
	appearFadeLayer: function() {
		new Effect.Appear('fadeLayerWrapper', {duration: .2, from: 0, to: .65});
	},
	
	prepareFog: function() {
		this.setFadeLayerDims();
		this.appearFadeLayer();
	},
	
	create: function(w, h, content, type) {
		this.prepareFog();
		
		//new Effect.Appear('fadeLayerWrapper', {duration: .3, from: 0, to: .65, afterFinishInternal: function() {
			// Creo il popup
			var popup = FF.visual.createPopup();
			new Effect.Morph(popup, {
				style: {
					width:w+'px', 
					height:h+'px',
					top:Number(FF.getElementSize('contents')['h'] / 2 - (h/2)) + 'px', 
					left:Number(FF.getElementSize('contents')['w'] / 2 - (w/2)) + 'px'
				},
				duration: 0, 
				afterFinishInternal: function() {
					new Effect.Appear(popup, {duration: .2, afterFinishInternal: function() {
						popup.innerHTML = '<div class="fastEditContainer" id="fastEditWrapper"><div class="popupCloseButton"><a href="javascript:Animations.closePopup();"><strong>X</strong></a></div>';
						if(type == 'iframe') {
							popup.innerHTML += '<iframe style="margin-top: 20px" width="100%" height="345" border="0" frameborder="0" scrolling="no" src="'+content+'"></iframe>';
						} else if(type == 'DOM') {
							popup.appendChild(content);
						} else {
							popup.innerHTML += content;
						}
						popup.innerHTML += '</div>';
						$('contents').appendChild(popup);
						return popup;
					}});
				}
			});
		//}});
		
	},
	
	setContent: function(content) {
		
	}
	
}






